//
//  BettingConViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-4-26.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BettingConViewController.h"
#import "UserDataAndSetting.h"

@interface BettingConViewController ()

@end

@implementation BettingConViewController

@synthesize lotteryTtpe=_lotteryTtpe;
@synthesize issueNumber=_issueNumber;
@synthesize lotteryDate=_lotteryDate;
@synthesize selectNumbers=_selectNumbers;
@synthesize note=_note;
@synthesize multiple=_multiple;
@synthesize addNumber=_addNumber;
@synthesize money=_money;


-(void)dealloc{

    [bettingConTableView release];
    [_issueNumber release];
    [_lotteryDate release];
    [_selectNumbers release];
    [textRedColor release];
    [textBlackColor release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    textRedColor=[[UIColor redColor] retain];
    textBlackColor=[[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f] retain];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark- UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSInteger rows=0;
    switch (section) {
        case 0:
            rows=3;
            break;
        case 1:
            rows=3;
            break;
        case 2:
            rows=1;
            break;
        default:
            rows=0;
            break;
    }
    return rows;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellString=@"BettingCon";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellString];
    if (cell) {
        cell=nil;
    }
    cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString] autorelease];
    
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            cell.textLabel.text=@"彩种";
            UILabel *label=[UILabel creatBettingCellLabelWithFrame:CGRectMake(100.0f, 0.0f, 200.0f, 45.0f)];
            label.text=@"双色球";
            [label reSetLabelFrame];
            [cell.contentView addSubview:label];
            [label release];
        }else if(indexPath.row==1){
            cell.textLabel.text=@"期号";
            UILabel *label=[UILabel creatBettingCellLabelWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
            label.text=self.issueNumber;
            [label reSetLabelFrame];
            [cell.contentView addSubview:label];
            [label release];
            
            UILabel *dateLabel=[UILabel creatBettingConRedLabelWithFrame:CGRectMake(0.0f, 0.0f,0.0f, 0.0f)];
            dateLabel.text=self.lotteryDate;
            [dateLabel sizeToFit];
            dateLabel.frame=CGRectMake(label.frame.origin.x+label.frame.size.width+10.0f,label.frame.origin.y-(label.frame.size.height-dateLabel.frame.size.height), dateLabel.frame.size.width, dateLabel.frame.size.height);
            [cell addSubview:dateLabel];
            [dateLabel release];
        }else if (indexPath.row==2) {
            cell.textLabel.text=@"选号";
            float tempWidth=100.0f;
            for (int i=0; i<_selectNumbers.count; i++) {
                NSDictionary *dic=[_selectNumbers objectAtIndex:i];
                NSArray *data=[dic objectForKey:@"data"];
                UIColor *color=[dic objectForKey:@"color"];
                UILabel *label=[UILabel creatBettingConinfoCellWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
                NSMutableString *tempString=[NSMutableString new];
                
                for (int j=0; j<data.count; i++) {
                    if (data.count-1!=j) {
                        [tempString appendFormat:@"%@,",[data objectAtIndex:i]];
                    }else {
                        [tempString appendFormat:@"%@",[data objectAtIndex:i]];
                    }
                }
                label.text=tempString;
                [tempString release];
                label.textColor=color;
                [label sizeToFit];
                label.frame=CGRectMake(tempWidth, 45.0f/2-label.frame.size.height/2, label.frame.size.width, label.frame.size.height);
                tempWidth+=label.frame.size.width;
                [cell.contentView addSubview:label];
                [label release];
                
                if (label.frame.origin.x+label.frame.size.width>tableView.frame.size.width-20.0f-20.0f) {
                    label.frame=CGRectMake(label.frame.origin.x, label.frame.origin.y, tableView.frame.size.width-20.0f-label.frame.origin.x, label.frame.size.height);
                    break;
                }
                
                if (i!=(_selectNumbers.count-1)) {
                    UILabel *addLabel=[UILabel creatBettingConinfoCellWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
                    addLabel.text=@"+";
                    [addLabel sizeToFit];
                    addLabel.frame=CGRectMake(tempWidth, label.frame.size.height/2-addLabel.frame.size.height/2+label.frame.origin.y, addLabel.frame.size.width, addLabel.frame.size.height);
                    [cell.contentView addSubview:addLabel];
                    [addLabel release];
                    tempWidth+=addLabel.frame.size.width;
                }
            }
        }
    }else if(indexPath.section==1){
    
        cell.textLabel.text=@"注数";
    }
    cell.textLabel.font=[UIFont boldSystemFontOfSize:17.0f];
    
    return cell;
}

@end
